#!/usr/bin/python3
"""
    ----coding:utf-8----
    @Author   : sobo
    @Time     : 2018/3/29 下午2:58
    @Software : 
    @File     : task.py

"""
from celery import task
from django.core.mail import send_mail
from .models import Order


def order_created(order_id):
    '''
    任务在成功创建订单时发送电子邮件通知。
    '''

    order = Order.objects.get(id=order_id)
    subject = '订单：{}'.format(order_id)
    message = '{}，您好。\n\n您以成功下单。\n您的该订单编号为：{}。'.format(order.name, order.id)
    mail_sent = send_mail(subject, message, 'admin@myshop.com', [order.email])
    return mail_sent
